home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / compiler / buffcode.ml < prev    next >
Encoding:
Text File  |  1993-09-24  |  750 b   |  41 lines  |  [TEXT/MPS ]

  1. (* To buffer bytecode during emission *)
  2.  
  3. #open "obj";;
  4. #open "misc";;
  5. #open "config";;
  6. #open "opcodes";;
  7.  
  8. let out_buffer = ref (create_string 64)
  9. and out_position = ref 0
  10. ;;
  11.  
  12. let realloc_out_buffer () =
  13.   let new_buffer = create_string (2 * string_length !out_buffer) in
  14.     replace_string new_buffer !out_buffer 0;
  15.     out_buffer := new_buffer;
  16.     ()
  17. ;;
  18.  
  19. let init_out_code () =
  20.   out_position := 0;
  21.   ()
  22. ;;
  23.  
  24. let out b =
  25.   if !out_position >= string_length !out_buffer then realloc_out_buffer();
  26.   set_nth_char !out_buffer !out_position (fchar__char_of_int b);
  27.   incr out_position
  28. ;;
  29.  
  30. let out_short s =
  31.   out s; out (lshift_right s 8)
  32. ;;
  33.  
  34. let out_long l =
  35.   out l;
  36.   out (lshift_right l 8);
  37.   out (lshift_right l 16);
  38.   out (lshift_right l 24)
  39. ;;
  40.  
  41.